<%@ page contentType="text/html;charset=utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<div id="header">
    <div class="container">
        <div id="welcomeLine" class="row">
            <div class="span6">Welcome!
            <c:if test="${!empty user }">
            <strong> ${user.lastname }${user.firstname }</strong>
			<a href="${pageContext.request.contextPath }/user/logout"><b>Logout</b></a>            
            </c:if>
            <c:if test="${empty user }">
			<a href="login.jsp"><b>Login</b></a>            
            </c:if>
            </div>
            <div class="span6">
                <div class="pull-right">
                    <a href=""><span class="">Fr</span></a>
                    <a href=""><span class="">Es</span></a>
                    <span class="btn btn-mini">En</span>
                    <a href=""><span>&pound;</span></a>
                    <span class="btn btn-mini">$${totalPrice - totalDiscount + totalTax }0</span>
                    <a href=""><span class="">$</span></a>
                    <a href="${pageContext.request.contextPath }/prototype/addcart"><span class="btn btn-mini btn-primary"><i
                            class="icon-shopping-cart icon-white"></i> [ ${counts } ] Itemes in your cart </span> </a>
                </div>
            </div>
        </div>
        <!-- Navbar ================================================== -->
        <div id="logoArea" class="navbar">
            <a id="smallScreen" data-target="#topMenu" data-toggle="collapse" class="btn btn-navbar">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </a>
            <div class="navbar-inner">
                <a class="brand" href="${pageContext.request.contextPath }/prototype/second"><img src="${path}/themes/images/logo.png" alt="Bootsshop"/></a>
                <form class="form-inline navbar-search" method="post" action="list">
                    <input id="srchFld" class="srchTxt" name="productname" type="text"/>
                    <select class="srchTxt" name="types">
                        <option value="0">All</option>
                       <!--  <option value="1">CLOTHES</option>
                        <option value="2">FOOD AND BEVERAGES</option>
                        <option value="3">HEALTH & BEAUTY</option>
                        <option value="4">SPORTS & LEISURE</option>
                        <option value="5">BOOKS & ENTERTAINMENTS</option> -->
                        <c:forEach items="${childrenCategories }" var="c">
                        	<option value="${c.id }">${c.name }</option>
                        </c:forEach>
                    </select>
                    <button type="submit" id="submitButton" class="btn btn-primary">Go</button>
                </form>
                <ul id="topMenu" class="nav pull-right">
                    <li class=""><a href="${pageContext.request.contextPath }/prototype/special">Specials Offer</a></li>
                    <li class=""><a href="normal.jsp">Delivery</a></li>
                    <li class=""><a href="contact.jsp">Contact</a></li>
                    <li class="">
                        <a href="#login" role="button" data-toggle="modal" style="padding-right:0"><span
                                class="btn btn-large btn-success">Login</span></a>
                        <div id="login" class="modal hide fade in" tabindex="-1" role="dialog" aria-labelledby="login"
                             aria-hidden="false">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                                <h3>Login Block</h3>
                            </div>
                            <div class="modal-body">
                                <form class="form-horizontal loginFrm" action="user/login" method="post">
                                    <div class="control-group">
                                        <input type="text" name="email" id="inputEmail" placeholder="Email">
                                    </div>
                                    <div class="control-group">
                                        <input type="password" name="password" id="inputPassword" placeholder="Password">
                                    </div>
                                    <div class="control-group">
                                        <label class="checkbox">
                                            <input type="checkbox"> Remember me
                                        </label>
                                    </div>
                                <button type="button" class="btn btn-success" id="loginbtn">Sign in</button>
                                <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
                                <span id="myspan" style="color:red"></span>
                                </form>
                            </div>
                        </div>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="js/jquery-1.7.2.js"></script>
<script type="text/javascript">
	/*function login(){
		var email = document.getElementsByName("email").item(0).value;
		var password = document.getElementsByName("password").item(0).value;
		
		var xmlHttp = new XMLHttpRequest();
		var url = "${pageContext.request.contextPath }/user/login?user.email="+email+"&user.password="+password;
		xmlHttp.open("get",url,true);
		xmlHttp.send();
		xmlHttp.onreadystatechange = function(){
			if(xmlHttp.status == 200){
				if(xmlHttp.readyState == 4){
					var s = xmlHttp.responseText;
					var user = JSON.parse(s);
					if(user==null){
						document.getElementById("myspan").innerHTML="Username or password error!";
					}else{
						location.href="${pageContext.request.contextPath }/index.jsp";
					}
				}
			}
		};
	}*/
    $(function () {
        $("#loginbtn").click(function () {
            var email = $("#inputEmail").val();
            var password = $("#inputPassword").val();
            $.get("${path}/user/login",{"user.email":email,"user.password":password}, function (user) {
                if(user==null){
                    document.getElementById("myspan").innerHTML="Username or password error!";
                }else{
                    location.href="${path }/index.jsp";
                }
            });
        });
    });
</script>